package luj.game.robot.internal.net.http.receive;

import luj.ava.stream.StreamX;
import luj.game.robot.api.network.http.RobotHttpHandler;

import java.util.List;
import java.util.stream.Collectors;

final class HParamImpl implements RobotHttpHandler.Param {

  @Override
  public String name() {
    return _name;
  }

  public boolean exists() {
    return _value != null;
  }

  public String asStr() {
    return _value.get(0);
  }

  public int asInt() {
    return Integer.parseInt(asStr());
  }

  public long asLong() {
    return Long.parseLong(asStr());
  }

  public double asDouble() {
    return Double.parseDouble(asStr());
  }

  public <T> List<T> asList(Class<T> type) {
    return StreamX.from(_value)
        .map(s -> HttpParamValueParser.GET.parse(type, s))
        .collect(Collectors.toList());
  }

//  public abstract List<String> getRawValue();

  String _name;
  List<String> _value;
}
